<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./serviceConfig.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    <p:panel>
                        <table border="0" cellspacing="5">
                            <tbody>
                                <tr>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Đầu số     <p:inputText value="#{d2HelpConfigBean.selected.cpNumber}"/>
                                            Tỉnh*    
                                            <p:selectOneMenu id="d2HelpProvinces" value="#{d2HelpConfigBean.selected.param}">
                                                <f:selectItem itemLabel="Miền Bắc - MB" itemValue="MB"/>
                                                <f:selectItems value="#{d2HelpConfigBean.provinceMap}"/>
                                            </p:selectOneMenu>
                                        </h:panelGrid>
                                    </td>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Ngày bắt đầu hiệu lực 
                                            <p:calendar value="#{d2HelpConfigBean.selected.startEffect}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                                        required="true" requiredMessage="Bạn chưa chọn ngày bắt đầu hiệu lực"> 
                                                <p:ajax event="blur" listener="#{d2HelpConfigBean.onChangeStartDate()}" update="d2HelpEndDate d2HelpProvinces"/>
                                            </p:calendar>
                                            Ngày kết thúc hiệu lực 
                                            <p:calendar id="d2HelpEndDate" value="#{d2HelpConfigBean.selected.endEffect}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                                        required="true" requiredMessage="Bạn chưa chọn ngày hết hiệu lực"/>
                                            Nội dung trả về <p:inputTextarea value="#{d2HelpConfigBean.selected.content}" onkeyup="countContentChar(this, 'd2HelpCharCnt')"/>
                                            <h:outputText/>
                                            <span id="d2HelpCharCnt">Tin 1: 0 ký tự</span>
                                        </h:panelGrid>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!d2HelpConfigBean.edit}" action="#{d2HelpConfigBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{d2HelpConfigBean.edit}" action="#{d2HelpConfigBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{d2HelpConfigBean.resetToCreateForm()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
                <br/>
                <h:form>
                    Xem từ ngày 
                    <p:calendar value="#{d2HelpConfigBean.startViewDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"/>
                    đến ngày 
                    <p:calendar value="#{d2HelpConfigBean.endViewDate}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"/>
                    <p:commandButton value="Hiển thị" update="table" action="#{d2HelpConfigBean.resetToCreateForm()}"/>
                    <br/>
                    <br/>

                    <p:dataTable id="table" value="#{d2HelpConfigBean.list}" var="item" paginator="#{d2HelpConfigBean.list.size() >20}" rows="20" 
                                 selection="#{d2HelpConfigBean.selectedList}" selectionMode="multiple" resizableColumns="true">

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{d2HelpConfigBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="d2HelpDeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{d2HelpConfigBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="d2HelpDeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Đầu số" sortBy="#{item.cpNumber}">
                            #{item.cpNumber}
                        </p:column>
                        <p:column headerText="Bắt đầu" sortBy="#{item.startEffect}">
                            <h:outputText value="#{item.startEffect}">
                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Kết thúc" sortBy="#{item.endEffect}">
                            <h:outputText value="#{item.endEffect}">
                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Tham số" sortBy="#{item.param}">
                            #{item.param}
                        </p:column>
                        <p:column headerText="Nội dung trả về" sortBy="#{item.content}">
                            #{item.content}
                        </p:column>
                    </p:dataTable>

                    <p:confirmDialog modal="true" message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     hideEffect="explode"  
                                     header="Xác nhận" severity="alert" widgetVar="d2HelpDeleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="d2HelpDeleteConfirm.hide()"  
                                         action="#{d2HelpConfigBean.remove()}"/>
                        <p:commandButton value="Không" onclick="d2HelpDeleteConfirm.hide()" type="button" />   

                    </p:confirmDialog>

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>

